
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <title>新零售商城后台首页</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/style/admin.css" media="all">
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-input-inline" style="width:100px;">
                    <select name="state" id="state"  lay-verify="required" lay-filter="state" class="select" lay-verify="type">
                        <option value="-1">全部</option>
                        <option value="1">正常</option>
                        <option value="0">冻结</option>
                    </select>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">ID</label>
                    <div class="layui-input-block">
                        <input type="text" name="id" id="id" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">会员编号</label>
                    <div class="layui-input-block">
                        <input type="text" name="userNo" id="userNo" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
				<div class="layui-inline">
                    <label class="layui-form-label">会员姓名</label>
                    <div class="layui-input-block">
                        <input type="text" name="userName" id="userName" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
				<div class="layui-inline">
                    <label class="layui-form-label">联系电话</label>
                    <div class="layui-input-block">
                        <input type="text" name="phone" id="phone" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
				<div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-search" onclick="SelectData()">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
				<div class="layui-inline" style="float:right">
					<button class="layui-btn layuiadmin-btn-admin" data-type="add" onclick="WinOpenAdd();">添加</button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <table class="layui-hide" id="test"></table>

            <script type="text/html" id="barDemo">
                <a class="layui-btn layui-btn-xs" lay-event="edit" onclick="WinOpenEdit({{d.userId}})" >编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" onclick="WinOpenDel({{d.userId}})">删除</a>
            </script>

        </div>
    </div>
</div>
<script src="/layui/layui.js"></script>
<script src="/layui/jquery.min.js"></script>
<script src="/js/common.js"></script>
<script>
    var table;
    layui.use('table', function(){
        table = layui.table
            ,form = layui.form;

        table.render({
            elem: '#test'
            ,url:'/user?url=User%2FList'
            ,cellMinWidth: 80
            ,cols: [[
                {field:'id', title:'ID'}
                ,{field:'no', title:'编号'}
                ,{field:'rank', title:'等级'}
                ,{field:'name', title:'姓名'}
                ,{field:'nick', title:'昵称'}
                ,{field:'phone', title:'电话'}
                ,{field:'cardId', title: '身份证'}
                ,{field:'registerTime',width:200 , title: '注册时间',templet :function (row){return createTime(row.registerTime);}}
                ,{field:'edit', title:'编辑', templet: '#barDemo', unresize: true}
            ]]
            ,page: true
            ,id: 'testReload'
        });

        //监听表格复选框选择
        table.on('checkbox(demo)', function(obj){
            console.log(obj)
        });


    });





    function createTime(v){
        return new Date(v).toLocaleString()
    }
    /**重写toLocaleString方法*/
    Date.prototype.toLocaleString = function() {
        var y = this.getFullYear();
        var m = this.getMonth()+1;
        m = m<10?'0'+m:m;
        var d = this.getDate();
        d = d<10?("0"+d):d;
        var h = this.getHours();
        h = h<10?("0"+h):h;
        var M = this.getMinutes();
        M = M<10?("0"+M):M;
        var S=this.getSeconds();
        S=S<10?("0"+S):S;
        return y+"-"+m+"-"+d+" "+h+":"+M+":"+S;}


    function SelectData() {
        //数据刷新
        var id = $('#id').val();
        var userNo = $('#userNo').val();
        var userName = $('#userName').val();
        var state = $('#state').val();
        var phone = $('#phone').val();
        var url="/user?url=User%2FList";
        if(userNo!=null && $.trim(userNo)!="")
        {
            url+="&no="+userNo+"&";
        }
        if(id!=null && $.trim(id)!="")
        {
            url+="&id="+id+"&";
        }
        if(userName!=null && $.trim(userName)!="")
        {
            url+="&name="+userName+"&";
        }
        if(phone!=null && $.trim(phone)!="")
        {
            url+="&phone="+phone+"&";
        }
        if(state!=null && state!="-1")
        {
            url+="&state="+state;
        }

        //alert(url);
        //执行重载
        table.reload('testReload', {
            url:url,
            page: {
                curr: 1 //重新从第 1 页开始
            }
        });
    }

    /*添加会员*/
	function WinOpenAdd(){
		window.parent.WinOpenAdd(this,"/user/user/add.html","添加会员",330,400,1);
	}	
	
	/*编辑会员*/
	function WinOpenEdit(categoryId){
		window.parent.WinOpenEdit(this,"/user/user/edit.html?categoryId="+categoryId,"修改会员资料",330,400,1);
	}
	
	/*删除会员*/
	function WinOpenDel(categoryId){
		window.parent.WinOpenEdit(this,"/user/user/del.html?categoryId="+categoryId,"删除会员",340,300,1);
	}
	
</script>


</body>
</html>